import { getAreaObj, regularRule } from '@/utils/util'

export const formConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	labelWidth: '120px',
	column: [
		{ label: '任务名称', prop: 'taskName',span: 8 },
		{ label: '隐患评估表', prop: 'tableTemplateName',span: 8 },
		{ label: '评估第三方', prop: 'evaluateThirdParties',span: 8 },
		{ label: '添加人', prop: 'createUserName',span: 8 },
		{ label: '添加时间', prop: 'createTime',span: 8 },
		{
			label: '评估时间',
			prop: 'evaluateTime',
			span: 8
		},
		{
			label: '评估结果',
			prop: 'result',
			dicData: [
				{ label: '合格', value: 0 },
				{ label: '整改', value: 1 },
			],
			span: 8
		},	
	],
}

export const tableConfig = {
	stripe: true,
	border: true,
	columns: [
		{ label: '任务名称', prop: 'taskName' },
		{ label: '隐患评估表', prop: 'tableTemplateName' },
		{ label: '评估第三方', prop: 'evaluateThirdParties' },
		{
			label: '评估时间',
			prop: 'evaluateTime',
		},
		{
			label: '评估结果',
			prop: 'result',
			dicData: [
				{ label: '合格', value: 0 },
				{ label: '整改', value: 1 },
			],
		},	
		{
			label: '操作',
			prop: 'menu',
			width: 100,
			fixed: 'right',
		},
	],
}

export const api = {
	index: 'view_pbHazardAssessment_page',
}
export const baseConfig = {
	pageName: '隐患评估记录',
	dictcodes: [],
	rowKey: 'id',
	addLabel: '新增',
	tipLabel: 'personName',
	exportMqTopic: '/ning/export/',
	api,
	auth: {
		...api,
	},
	paramsObj: {
		source: 1,
	},
	menuBtn: [
		{
			icon: 'detail',
			label: '查看',
			type: 'primary',
			operate: 'detail',
			auth: api.index,
			text: true,
			show: true,
		},
	],
	dialogConfig: {
		width: '55%',
	},
	formConfig,
	tableConfig,
	detailConfig: formConfig,

	operateFormate: async (form, type) => {
		return new Promise((resolve, reject) => {
			const areaObj: any = getAreaObj(form, '', 'get')
			resolve({
				...form,
				...areaObj,
				areas: areaObj.areaIds,
			})
		})
	},

	saveFormate: async (form, type) => {
		return new Promise((resolve, reject) => {
			const areaObj: any = getAreaObj(form.areas)
			resolve({
				...form,
				...areaObj,
				areas: undefined,
			})
		})
	},
	beforeOnLoadFormate: async (params) => {
		return new Promise((resolve, reject) => {
			const areaObj: any = getAreaObj(params.areas)
			resolve({
				...params,
				...areaObj,
				areas: undefined,
			})
		})
	},
}
